import type {
  OrderResult,
  OrderCreateParams,
  OrderCreateResult,
  OrderPreResult,
  OrderLogisticResult,
  OrderListParams,
  OrderListResult
} from '@/types/order'
import http from '@/utils/http'

/**
 * 获取会员-预付订单
 */
export const getMemberOrderPreAPI = () => {
  return http<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre'
  })
}

/**
 * 获取会员-立即购买预付订单
 */
export const getMemberOrderPreNowAPI = (data: {
  skuId: string
  count: string
  addressId?: string
}) => {
  return http<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre/now',
    data
  })
}


/**
 * 提交订单
 * @param data 订单参数
 */
export const postMemberOrderAPI = (data: OrderCreateParams) => {
  return http<OrderCreateResult>({
    method: 'POST',
    url: '/member/order',
    data
  })
}


/**
 * 获取会员订单详情
 * @param id 订单id
 */
export const getMemberOrderDetailAPI = (id: string) => {
  return http<OrderResult>({
    method: 'GET',
    url: `/member/order/${id}`
  })
}


/**
 * 获取微信支付参数
 * @param orderId 订单id
 */
export const getOrderPaymentAPI = (orderId: string) => {
  return http<WechatMiniprogram.RequestPaymentOption>({
    method: 'GET',
    url: '/pay/wxPay/miniPay',
    data: {
      orderId
    }
  })
}


/**
 * 模拟支付-内测版
 * @param orderId 订单id
 */
export const getOrderPaymentMockAPI = (orderId: string) => {
  return http({
    method: 'GET',
    url: '/pay/mock',
    data: {
      orderId
    }
  })
}

/**
 * 模拟发货
 * @param orderId 订单id
 */
export const getMemberOrderConsignmentAPI = (orderId: string) => {
  return http({
    method: 'GET',
    url: `/member/order/consignment/${orderId}`
  })
}


/**
 * 确认收货
 * @param id 订单id
 */
export const putMemberOrderReceiptAPI = (id: string) => {
  return http<OrderResult>({
    method: 'PUT',
    url: `/member/order/${id}/receipt`
  })
}

/**
 * 获取订单物流
 * @param id 订单id
 */
export const getMemberOrderLogisticsAPI = (id: string) => {
  return http<OrderLogisticResult>({
    method: 'GET',
    url: `/member/order/${id}/logistics`
  })
}


/**
 * 删除订单
 * @description 仅在订单状态为待评价，已完成，已取消时，可删除订单。
 * @param data ids 订单集合
 */
export const deleteMemberOrderAPI = (data: { ids: string[] }) => {
  return http({
    method: 'DELETE',
    url: `/member/order`,
    data,
  })
}


/**
 * 根据状态获取订单列表
 * @param data 查询参数
 */
export const getMemberOrderByStateAPI = (data: OrderListParams) => {
  return http<OrderListResult>({
    method: 'GET',
    url: '/member/order',
    data
  })
}
